#include "WinUnit.h"
#include "HandHistoryParser.h"
#include "HandInfo.h"
#include "AmtWonLostHandInfoBuilder.h"
#include "HandInfoExtractor.h"
#include "Player.h"
#include "Action.h"
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <functional>
#include <direct.h>

using namespace std;
using namespace tr1;

namespace
{
	HandHistoryParser parser = HandHistoryParser();
	char workingDir[_MAX_PATH];
	string WORKING_DIR;
	string SAMPLES_DIR;
	string PROJECT_DIR;	
}

FIXTURE(AmtWonLostHandInfoBuilderFixture);

SETUP(AmtWonLostHandInfoBuilderFixture)
{
	_getcwd(workingDir, _MAX_PATH);
	WORKING_DIR = string(workingDir);
	SAMPLES_DIR = WORKING_DIR + "\\..\\..\\..\\data\\samples\\";
	PROJECT_DIR = WORKING_DIR + "\\..\\Pokernut.Parsing.Tests\\";
}

TEARDOWN(AmtWonLostHandInfoBuilderFixture)
{
	// clean up after yourself here!
}

bool AssertWinnings(HandInfo info, string playerName, float amtWonLost)
{
	return (info.PlayerInfo(playerName).AmountWonLost() == amtWonLost);
}

bool TestAmtWonLost_CaseOne()
{
	list<Hand> & hands = parser.Parse(SAMPLES_DIR + "singlehand.txt");
	AmtWonLostHandInfoBuilder b;
	HandInfo info(hands.front());
	b.Fill(info, hands.front());

	bool bReturnVal;
	bReturnVal = AssertWinnings(info, "Tranqville", 26);
	bReturnVal = bReturnVal & AssertWinnings(info, "umpa21", -2);
	bReturnVal = bReturnVal & AssertWinnings(info, "heroyay", 0);
	bReturnVal = bReturnVal & AssertWinnings(info, "lindevall87", 0);
	bReturnVal = bReturnVal & AssertWinnings(info, "mixmastr", -26);

	return bReturnVal;
}

bool TestAmtWonLost_CaseTwo()
{
	list<Hand> & hands = parser.Parse(SAMPLES_DIR + "singlehand2.txt");
	AmtWonLostHandInfoBuilder b;
	HandInfo info(hands.front());
	b.Fill(info, hands.front());

	bool bReturnVal;
	bReturnVal = AssertWinnings(info, "gnat777", -12);
	bReturnVal = bReturnVal & AssertWinnings(info, "Kete 1955", -0.5);
	bReturnVal = bReturnVal & AssertWinnings(info, "diman21", -1);
	bReturnVal = bReturnVal & AssertWinnings(info, "Fabinho89", 0);
	bReturnVal = bReturnVal & AssertWinnings(info, "heroyay", 12.25);
	bReturnVal = bReturnVal & AssertWinnings(info, "kim1230", 0);
	
	return bReturnVal;
}

BEGIN_TESTF(AmtWonLostHandInfoBuilderTest, AmtWonLostHandInfoBuilderFixture)
{
	WIN_ASSERT_TRUE(TestAmtWonLost_CaseOne() & TestAmtWonLost_CaseTwo()
		);
}
END_TESTF